<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1.0"/>
    <meta http-equiv="X-UA-Compatible" content="ie=edge"/>
    <link rel="stylesheet" href="../css/seat.css"/>
    <script type="text/javascript"src="../jquery-3.6.0.js"></script>
    <script>
        $(function (){
            $(".seat:not(.occupied)").click(function (){
                var seatNotSelected=$(this).attr("value");
                var row_column=seatNotSelected.split(" ");
                var row=row_column[0];
                var column=row_column[1];
                $("#row").text("行:"+row);
                $("#row").val(row);
                $("#column").text("列:"+column);
                $("#column").val(column);
            })
            $("#confirm").bind('click',function (){
                alert("购票成功");
                setTimeout(function (){
                    $("#buy").submit();
                },1000);
            })
        })
    </script>
    <title>挑选座位</title>
</head>
<body>
    <?php
        include ("../service/MovieService.php");
    ?>
    <div class="movie-container">
        <label>您挑选的电影为: </label>
        <a>
            <?php
                $movieService=new MovieService();
                $movie_id=$_GET["movie_id"];
                $movie_name=$movieService->getMovieName($movie_id);
                echo $movie_name;
            ?>
        </a>
        <br>
        <label>您选择的电影院为:</label>
        <a>
            <?php
                $cinema_id=$_GET["cinema_id"];
                $cinema_name=$movieService->getCinemaById($cinema_id);
                echo $cinema_name;
            ?>
        </a>
    </div>
    <ul class="showcase">
        <li>
            <div class="seat"></div>
            <small>Avaliable</small>
        </li>
        <li>
            <div class="seat seatshow"></div>
            <small>Selected</small>
        </li>
        <li>
            <div class="seat occupied"></div>
            <small>Occupied</small>
        </li>
    </ul>

    <div class="seat-container">
        <div class="screen"></div>
        <?php
            $seatInfo=$movieService->getSeatInfo($cinema_id,$movie_id,1);
            for($i=0;$i<sizeof($seatInfo);$i++) {
                $seat_row[$i] = $seatInfo[$i]['seat_row'];
                $seat_column[$i] = $seatInfo[$i]['seat_column'];
            }
            for($i=1;$i<=6;$i++){
                for($j=1;$j<=8;$j++){
                    $seat_row_column[$i][$j]=0;
                }
            }
            for($i=0;$i<sizeof($seatInfo);$i++){
                $row=$seat_row[$i];
                $column=$seat_column[$i];
                $seat_row_column[$row][$column]=1;
            }
            for($i=1;$i<=6;$i++){
                echo "<div class='row'>";//
                for($j=1;$j<=8;$j++){
                    if($seat_row_column[$i][$j]==1){
                        echo "<div class='seat occupied'></div>";
                    }else{
                        echo "<div class='seat' value='".$i." ".$j."'></div>";
                    }
                }
                echo "</div>";
            }
        ?>
        <div class="text">
            一次只能购买一张票,您选择的座位为--
            <form method='get' action='submit.php'id="buy">
                <input name='row'id='row'>
                <input name='column'id='column'>
                <?php
                    echo "<input name='cinema_id'id='cinema_id'value='".$cinema_id."'>";
                    echo "<input name='movie_id'id='movie_id'value='".$movie_id."'>";//SADASDSA
                ?>
                <button id="confirm">确定选票并支付</button>
            </form>
        </div>
    </div>
    <script src="../js/seat.js"></script>
</body>
</html>